
/*
*Released on 28th June 2008.
*Any violations can be reported at paritosh@wikiocean.net
*What is treated as violations can be found at www.wikiocean.net/ppl1-voilations*
******************************************************************************
* The contents of this file are subject to POOL Public License 1.0 and later.
* POOL Public License is based on Affero GPL v3 and additional conditions.
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the Affero GPL v3 License at http://www.gnu.org/licenses/agpl.html
* You may obtain a copy of the POOL Public License 1.0 or later at www.wikiocean.net/license/ppl.html
* Software distributed under POOL Public License 1.0 is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Initial Developer of the Original Code is Paritosh Pungaliya (C) 2008. All Rights Reserved.
******************************************************************************
* Objective of the additional terms (license)
* 1) Is to extend the software freedom to freedom to work.
* 2) To ensure that knowledge is free from monopoly of agencies.
* 3) To avoid a situation where big corporate or investor can buy out free software groups and companies and then start milking the communities built around it.
* (this trend can be seen how the freedom is curtailed in companies that get Venture Capital funding.)
******************************************************************************
*/

package  query.query;


import java.util.Hashtable;
import java.util.Vector;

import logger.PoolLogger;

import file.SearchRecord;
import dbmanager.GetIdName;
/**
 * 
 * @author mahendra
 * <pre> ResultSet is also a property of Query. It is used when the report is already existed having the condition which satisfy the condition which user want to put.  
 *  It is helpful because no need to check the query or test the condition, because the value of the resultset is report which is existing report having the Storage property.
 * </pre>
 **/
public class Resultset implements Queryinterface
{
	String STORAGE="storage";
	GetIdName gid;
	String PATH="path";
	String Message;
	String buffer[];
	String StorageObject;
	String reporton;
	int QueryCount=1;
	String Key;
	String value;
	String tablename;
	String Querrybuffer[];
	String Query;
	SearchRecord sr;
	String ReportName;
	String Filename;
	String QUERY="query";
	String typeofreport;
	String TYPE="type";
	Hashtable<Object, Object> QueryMap = new Hashtable<Object, Object>();
	Hashtable<Object, Object> ReportMap = new Hashtable<Object, Object>();
	String Reportname;
	PoolLogger pl;
	
	
	public void queryProcess(){
		getResult();
	}
	
	
	public Resultset() {
		// logger
		pl = (PoolLogger) PoolLogger.getLogger(this.getClass().getName());
	}
	
	/**
	 * getResult Method return buffer form report storage
	 */
	public void getResult() 
	{
		try 
		{
			if(tablename.equals("") || tablename.equalsIgnoreCase("report_master"))
			{
				buffer =new String[1];
				buffer[0] = gid.getItem(StorageObject);
			}	
		} 
		catch (Exception e) 
		{
			Querrybuffer =new String[1];
			Querrybuffer[0] = gid.getItem(StorageObject);
			
		}
	}
	/**
	 * getbuffer()
	 * @return buffer
	 */
	public String[] getbuffer() 
	{
		return buffer;
	}
	/**
	 * setDbmanager method set Dbmanagaer object
	 * @param db is database object  
	 */
	public void initPool() 
    {
		gid = new GetIdName();
		PATH = gid.getId(PATH);
		TYPE = gid.getId(TYPE);
	}

	public void setMessage(String message) 
	{
		this.Message = message;
	}
	/**
	 * setbuffer method set buffer variable
	 * @param buffer
	 */
	public void setbuffer(String[] buffer) 
	{
		this.buffer = buffer;
	}

	public String getObject() 
	{	
		return StorageObject;
	}


	public String[] getQuerybuffer() 
	{
		return Querrybuffer;
	}
	/**
	 * getKey Method retrun key
	 */
	public String getkey() 
	{
		return Key;
	}
	/**
	 * gettablename Method return tablename
	 */
	public String gettablename() 
	{
		return tablename;
	}

	public String getvalue() 
	{
		return value;
	}

	public void initializeData() 
	{
		
	}
	/**
	 * setKey() method set key
	 * @param key
	 */
	public void setKey(String key) 
	{
		this.Key = key;
	}
	/**
	 * setObject() method takes parameter like:
	 * @param object
	 */ 
	public void setObject(String object) 
	{
		this.StorageObject = object;
	}



	public void setQuerybuffer(String[] Querybuffer) 
	{
		this.Querrybuffer =Querybuffer;
	}

	public void setValue(String value) 
	{
		this.value =  value;
	}

	public void settablename(String tablename) 
	{
		this.tablename = tablename;
	}

	public String getReportname() 
	{
		return Reportname;
	}

	public void setReportname(String Filename) 
	{
		this.Reportname = Filename;
	}

	public Hashtable<Object, Object> getQueryMap()
	{
		return QueryMap;
	}

	public void setQueryMap(Hashtable<Object, Object> QueryMap) 
	{
		this.QueryMap = QueryMap;
	}

	public String gettid() 
	{
		return null;
	}

	public void settid(String tid) 
	{
	
		
	}
	/**
	 * when process is add then addreport is call  
	 */
	@SuppressWarnings("unchecked")
	public void addReport() 
	{
		getResult();
		
			
	/*	 if(Querrybuffer==null)
			 Querrybuffer = buffer;
			 */
	
	
	}
	/**
	 * when process is mod then updateReport is call  
	 */
	public void updateReport() 
	{
		getResult();
			/*
			Report report =new Report(database,StorageObject);
			Hashtable<Object, Object> newreportmap =new Hashtable<Object, Object>();
			String typereport = report.GettypeofReport(); 
			newreportmap = report.getReportMap();
			newreportmap = ConvertToLower.convertHashKey(newreportmap);
				String path="";
				try 
				{
					query.condition.typereport.Typereport type; 
					Class C = Class.forName("query.condition.typereport."+CapitalChar.makeFirstCharCapital(typereport.trim()));
					type = (query.condition.typereport.Typereport)C.newInstance();
					type.setData(Key,value, database, newreportmap);
					path = type.getPath(gid.getItem(StorageObject));
				} catch (ClassNotFoundException e) 
				{
					e.printStackTrace();
				}
				catch (InstantiationException e) 
				{
					e.printStackTrace();
				}
				catch (Exception e) 
				{
					e.printStackTrace();
				}
			 StringBuffer tempbuffer;
			try 
			{
				RandomAccessFile raf =new RandomAccessFile(path,"r");
				 String line;
				 tempbuffer = new StringBuffer();
				 while((line=raf.readLine())!=null)
				 {
					 tempbuffer.append(line+"\n");
				 }
				 this.buffer = tempbuffer.toString().split("\n");
				 raf.close();
			} catch (FileNotFoundException e) 
			{
				e.printStackTrace();
			} catch (IOException e) 
			{
				e.printStackTrace();
			}
		
			
	/*	 if(Querrybuffer==null)
			 Querrybuffer = buffer;
			 */
	
	
	}

	public void setReportName(String Reportname) 
	{
		this.Reportname = Reportname; 
	}
	public void settypeofreport(String typeofreport) 
	{
	 this.typeofreport = typeofreport;
	}
	public void setReportmap(Hashtable<Object, Object> ReportMap) 
	{	
		this.ReportMap.putAll( ReportMap);
	}
	public void setreporton(String reporton) 
	{
		this.reporton = reporton;	
	}
	

	public void setQuery(String Query)
	{
		this.Query = Query;
	}
	public String getQuery() 
	{
		return Query;
	}
	
	public void setViewObject(String object, char ch) 
	{
	   this.StorageObject = gid.getId(object);	
	}
	@SuppressWarnings("unchecked")
	public void setViewObject(Vector<Object> PropertyMap) 
	{
		try {
			//this.StorageObject = ((Hashtable<Object, Object>)PropertyMap.get(0)).get("report").toString();
			this.StorageObject = gid.getId(PropertyMap.get(0).toString());
		} catch (Exception e) 
		{
			e.printStackTrace();
		}	
	}
	
	public int getcount() 
	{
		return QueryCount;
	}
	
	public String[] executeQuery(){return null;}
	
	
	public void setCount(int count) 
	{
		this.QueryCount = count;
	}
	
	public void setMaxcount(int count) {
		// TODO Auto-generated method stub
		
	}
	
	public void buildQuery() 
	{
		getResult();
	}
	
	public void setProcess(String process) {
		// TODO Auto-generated method stub
		
	}
	public void setConditionMap(Vector<Object> QueryMap)
	{
		
	}
}
